package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.ProjectInfoDto;
import com.crm.jdy.common.dto.WDisorInfoDto;
import com.crm.jdy.common.pojo.ProjectInfo;
import com.crm.jdy.common.pojo.WDisorInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.WDisorInfoService;
import com.crm.jdy.service.project.ProjectInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 退库列表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "wDisorInfo", description ="退库列表信息")
@RestController
@RequestMapping("/wDisorInfo")
public class WDisorInfoController{

    @Reference(version = "${service.version}", check = false)
    WDisorInfoService wDisorInfoService;

    @RateLimit()
    @ApiOperation("退库列表信息")
    @PostMapping("/seleteWDisorInfo")
    public ResultVo seleteWDisorInfo(@RequestBody WDisorInfoDto projectInfoDto){
        PageInfo<WDisorInfo> list = wDisorInfoService.seleteWDisorInfo(projectInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新退库列表信息")
    @PostMapping("/updateWDisorInfo")
    public ResultVo updateWDisorInfo(@ApiParam(value = "projectInfo", required = true)
                                      @Validated @RequestBody WDisorInfo projectInfo){
        boolean index = wDisorInfoService.updateWDisorInfo(projectInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加退库列表信息")
    @PostMapping("/addWDisorInfo")
    public ResultVo addWDisorInfo(@ApiParam(name = "projectInfo", required = false)
                                   @Validated @RequestBody WDisorInfo projectInfo){
        boolean list  = wDisorInfoService.addWDisorInfo(projectInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除退库列表信息")
    @DeleteMapping("deleteWDisorInfo/{disorId}")
    public ResultVo deleteWDisorInfo(@NotNull @ApiParam(name = "disorId", value = "disorId", required = true) @PathVariable String disorId){
        boolean b = wDisorInfoService.removeWDisorInfo(disorId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}